<include file="public@header"/>
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="photo[]" value="{filepath}">
        <input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
               style="width: 200px;" title="图片名称">
        <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
             onclick="imagePreviewDialog(this.src);">
        <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
    </li>
</script>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li ><a href="{:url('AdminGoods/index')}">商品列表</a></li>
        <li ><a href="{:url('AdminGoods/add')}">添加商品</a></li>
        <li class="active"><a href="{:url('AdminGoods/edit')}">编辑商品</a></li>
    </ul>
    <div class="row margin-top-20">
        <div class="col-md-2">
            <div class="list-group">
                <a class="list-group-item" href="#A" data-toggle="tab">通用信息</a>
                <a class="list-group-item" href="#B" data-toggle="tab">详细描述</a>
                <a class="list-group-item" href="#C" data-toggle="tab">商品相册</a>
                <a class="list-group-item" href="#D" data-toggle="tab">商品规格</a>
                <a class="list-group-item" href="#E" data-toggle="tab">其他信息</a>
            </div>
        </div>
        <div class="col-md-6">
            <form class="js-ajax-form" action="{:url('AdminGoods/editPost')}" method="post">
                <div class="tab-content">
                    <div class="tab-pane active" id="A">
                        <div class="form-group">
                            <label for="input-cat_id"><span class="form-required">*</span>商品分类</label>
                            <div>
                                <select class="form-control" name="cat_id" id="input-cat_id">
                                    <option value="">选择分类</option>
                                    {$category_tree}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-name"><span class="form-required">*</span>商品名称</label>
                            <div>
                                <input type="text" class="form-control" id="input-name" name="goods_name" required
                                       value="{$data.goods_name}">
                                <input type="hidden" class="form-control" id="input-id" name="id"
                                       value="{$data.id}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="input-goods_remark">商品描述</label>
                            <div>
                                <textarea class="form-control" name="goods_remark" id="input-goods_remark">{$data.goods_remark
                                    }</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-market_price"><span class="form-required">*</span>市场价（元）</label>
                            <div>
                                <input type="text" class="form-control" id="input-market_price" name="market_price"
                                       required value="{$data.market_price}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-cost_money"><span class="form-required">*</span>成本价（元）</label>
                            <div>
                                <input type="text" class="form-control" id="input-cost_money" name="cost_money"
                                       placeholder="用来计算利润" required value="{$data.cost_money}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-vip_money"><span class="form-required">*</span>会员价（元）</label>
                            <div>
                                <input type="text" class="form-control" id="input-vip_money" name="vip_money"
                                       required value="{$data.vip_money}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-weight">商品重量（克）</label>
                            <div>
                                <input type="text" class="form-control" id="input-weight" name="weight"
                                       value="{$data.weight}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-give_integral">赠送积分</label>
                            <div>
                                <input type="text" class="form-control" id="input-give_integral" name="give_integral"
                                       value="{$data.give_integral}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="input-is_new">是否新品</label>
                            <div>
                                <select class="form-control" name="is_new" id="input-is_new">
                                    <option value="0" <if condition="$data['is_new'] eq 0">selected</if>>不是</option>
                                    <option value="1" <if condition="$data['is_new'] eq 1">selected</if>>是</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-is_recommend">是否推荐</label>
                            <div>
                                <select class="form-control" name="is_recommend" id="input-is_recommend">
                                    <option value="0" <if condition="$data['is_recommend'] eq 0">selected</if>>不推荐</option>
                                    <option value="1" <if condition="$data['is_recommend'] eq 1">selected</if>>推荐</option>
                                </select>
                            </div>
                        </div>





                        <div class="form-group">
                            <label for="js-thumbnail-input">商品图片</label>
                            <div>
                                <input type="hidden" name="goods_img" class="form-control"
                                       id="js-thumbnail-input" value="{$data['goods_img']|default=''}">
                                <div>
                                    <a href="javascript:uploadOneImage('图片上传','#js-thumbnail-input');">
                                        <notempty name="$data['goods_img']">
                                            <img src="{$data['goods_img']|cmf_get_image_url}"
                                                 id="js-thumbnail-input-preview"
                                                 width="135" style="cursor: pointer"/>
                                        </notempty>
                                        <empty name="$data['goods_img']">
                                            <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                                 id="js-thumbnail-input-preview"
                                                 width="135" style="cursor: pointer"/>
                                        </empty>

                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane" id="B">
                        <div class="form-group">
                            <label for="content"></label>
                            <div>
                                <script type="text/plain" id="content" name="goods_content" style="height: 500px;">{:cmf_replace_content_file_url(htmlspecialchars_decode($data['goods_content']))}</script>
                            </div>
                        </div>

                    </div>
                    <div class="tab-pane" id="C">
                        <div class="form-group">
                            <label>相册</label>
                            <div>
                                <ul id="photos" class="pic-list list-unstyled form-inline">
                                    <notempty name="$photo">
                                        <foreach name="$photo" id="vo">
                                            <li id="saved-image{$key}">
                                                <input id="photo-{$key}" type="hidden" name="photo[]"
                                                       value="{$vo.url}">
                                                <input class="form-control" id="photo-{$key}-name" type="text"
                                                       name="photo_names[]" value="{$vo.alt}"
                                                       style="width: 200px;" title="图片名称">
                                                <img id="photo-{$key}-preview" src="{:cmf_get_image_preview_url($vo['url'])}" style="height:36px;width:
                                                36px;"
                                                     onclick="imagePreviewDialog(this.src);">
                                                <a href="javascript:uploadOneImage('图片上传','#photo-{$key}');">替换</a>
                                                <a href="javascript:(function(){$('#saved-image{$key}').remove();})();">
                                                    移除</a>
                                            </li>
                                        </foreach>

                                    </notempty>
                                </ul>
                                <a href="javascript:uploadMultiImage('图片上传','#photos','photos-item-tpl');"
                                   class="btn btn-default btn-sm">选择图片</a>

                            </div>
                        </div>

                    </div>
                    <div class="tab-pane" id="D">
                        <div class="form-group">
                            <label for="input-goods_type">商品类型</label>
                            <div>
                                <select class="form-control select_type" name="goods_type" id="input-goods_type">
                                    <option value="">请选择</option>
                                    <foreach name="goods_type" item="val">
                                        <option value="{$val.id}" <if condition="$val['id'] eq $data['goods_type']">selected</if>>{$val.name}</option>
                                    </foreach>
                                </select>
                            </div>
                        </div>
                        <div id="ajax_spec_data" class="tab-content tab-pane"><!-- ajax 返回规格--></div>

                    </div>
                    <div class="tab-pane" id="E">
                        <div class="form-group">
                            <label for="input-store_count">库存</label>
                            <div>
                                <input type="number" class="form-control" id="input-store_count" name="store_count"
                                       value="{$data.store_count}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-is_real">是否包邮</label>
                            <div>
                                <select class="form-control " name="is_free_shipping" id="input-is_free_shipping">
                                    <option value="0" <if condition="$data['is_free_shipping'] eq 0">selected</if>>包邮</option>
                                    <option value="1" <if condition="$data['is_free_shipping'] neq 0">selected</if>>不包邮</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group express_template" style="display: none">
                            <label for="input-is_real">选择运费模板</label>
                            <div>
                                <select class="form-control " name="express_template" id="input-express_template">
                                    <notempty name="express_template">
                                        <foreach name="express_template" id="ex">
                                            <option value="{$ex['id']}">{$ex['name']}</option>
                                        </foreach>
                                    </notempty>
                                    <empty name="express_template">
                                        <option value="0">暂无可用模板</option>
                                    </empty>
                                </select>
                            </div>
                        </div>


                        <div class="form-group">
                            <label for="input-is_real">是否实物</label>
                            <div>
                                <select class="form-control " name="is_real" id="input-is_real">
                                    <option value="1" <if condition="$data['is_real'] eq 1">selected</if>>实物</option>
                                    <option value="0" <if condition="$data['is_real'] eq 0">selected</if>>虚拟物品</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-is_on_sale">是否上架</label>
                            <div>
                                <select class="form-control " name="is_on_sale" id="input-is_on_sale">
                                    <option value="1" <if condition="$data['is_on_sale'] eq 1">selected</if>>上架</option>
                                    <option value="0" <if condition="$data['is_on_sale'] eq 0">selected</if>>下架</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <button type="submit" class="btn btn-primary js-ajax-submit">编辑</button>
                    <a class="btn btn-default" href="{:url('AdminGoods/index')}">{:lang('BACK')}</a>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script>
    $(function () {
        editorcontent = new baidu.editor.ui.Editor();
        editorcontent.render('content');
        try {
            editorcontent.sync();
        } catch (err) {
        }
    });

    $(document).ready(function(){
        $('.select_type').change(function(){
            var type_id = $(this).val();
            var goods_id= "{$data['id']}";
            $.ajax({
                type:'post',
                data:{type_id:type_id,id:goods_id},
                url:"{:url('AdminGoods/ajaxGetGoodSpecToGoodType')}",
                success:function(data){
                    $("#ajax_spec_data").html('');
                    $("#ajax_spec_data").append(data);
                    //alert('132');
                    ajaxGetSpecInput();	// 触发完  马上触发 规格输入框
                }
            });

        });
        $(".select_type").trigger('change');

        //获取到包邮状态 如果是不包邮,切换到保存的运费模板
        var is_free_shipping=$("select[name=is_free_shipping]").val();
        if(is_free_shipping == 1){
            $('.express_template').show();
            $("select[name=express_template]").val("{$data['is_free_shipping']}");
        }

        //包邮切换
        $("select[name=is_free_shipping]").change(function () {
            var v=$("select[name=is_free_shipping]").val();
            if(v == 1){
                //不包邮
                $('.express_template').show();
                var ex=$("select[name=express_template]").val();
                if(ex == 0){
                    $(".express_template").find('label').css('color','red');
                }
            }else{
                $('.express_template').hide();
            }
        });
    });
</script>
</body>
</html>